/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.actions;

import robocup.component.RobocupAgent;

/**
 * Init-Actions are used to instantiate an agent (player/coach/trainer) on
 * the server, which afterwards is controlled by this client.
 */
public class InitAction extends Action {

	/**
	 * The agent-type, which should be created:<br>
	 * <ul>
	 *   <li>FIELD_PLAYER [0]
	 *   <li>GOALIE [1]
	 *   <li>COACH [2]
	 *   <li>TRAINER [4]
	 * </ul>
	 * These constants are defined in AbstractAgent.
	 */
	private int type;

	/**
	 * The name of the team. All agents of the same team must connect with the
	 * same name.
	 */
	private String teamName;

	/**
	 * Constructor: Connecting an agent to the server
	 * 
	 * @param type
	 *            TRAINER, GOALIE, PLAYER or COACH
	 * @param teamName
	 *            the name of the team
	 */
	public InitAction(int type, String teamName) {
		this.type = type;
		this.teamName = teamName;
	}

	/**
	 * Returns the actions string representation:
	 * @return 
	 * (init [&lt;teamname&gt;] (version 9.4.5) [(goalie)])<br><br>
	 * 
	 * Teamname is not used for the trainer, because he doesn't belong to any
	 * team. The goalie-syntax is only inserted for type GOALIE.
	 * Note that the version refers to the server-version used. The given one 
	 * is compatible with all server versions higher or equal to 9.4.5.
	 */
	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("(init ");
		if (this.type != RobocupAgent.TRAINER)
			buf.append(this.teamName + " ");
		buf.append("(version 9.45)");
		if (this.type == RobocupAgent.GOALIE)
			buf.append(" (goalie)");
		buf.append(")");
		return buf.toString();
	}
}
